<template>
  <div class="auto">
    <form novalidate class="form-horizontal">
      <p class="bg-info text-center" style="padding: 8px;">上次购气信息</p>
      <div class="row" style="margin-top:6px;">
        <label for="f_pregas" class=" col-sm-2 control-label">预购气量:</label>
        <div class="col-sm-2">
          <input class="form-control"  type="number" v-model="model.f_pregas"
          v-scale = "[model.f_pregas, 2]" placeholder="预购气量" disabled>
        </div>
        <label for="f_preamount" class=" col-sm-2 control-label">预购金额:</label>
        <div class="col-sm-2">
          <input class="form-control"  type="number" v-model="model.f_preamount"
          v-scale = "[model.f_preamount, 2]" placeholder="预购气量" disabled>
        </div>
        <label for="f_canceltype" class=" col-sm-2 control-label">撤销类型:</label>
        <div class="col-sm-2">
          <input class="form-control"  type="text" v-model="model.f_canceltype" placeholder="撤销类型" disabled>
        </div>
      </div>
      <div class="row" style="margin-top:6px;">
        <label for="f_balance" class=" col-sm-2 control-label">上期结余:</label>
        <div class="col-sm-2">
          <input class="form-control"  type="number" v-model="model.f_balance"
          v-scale = "[model.f_balance, 2]" placeholder="上期结余" disabled>
        </div>
        <!-- <span class="col-sm-2 form-control-static">{{model.f_balance.toFixed(2)}}</span> -->
        <label for="f_curbalance" class="col-sm-2 control-label">本期结余:</label>
        <div class="col-sm-2">
          <input class="form-control"  type="number" v-model="model.f_curbalance"
          v-scale = "[model.f_curbalance, 2]" placeholder="本期结余" disabled>
        </div>
        <!-- <span class="col-sm-2 form-control-static">{{model.f_curbalance.toFixed(2)}}</span> -->
        <label for="f_curbalance" class="col-sm-2 control-label" style="width:15%">收款:</label>
        <div class="col-sm-2">
          <input class="form-control"  type="number" v-model="model.f_collection"
          v-scale = "[model.f_collection, 2]" placeholder="收款" disabled>
        </div>
        <!-- <span class="col-sm-2 form-control-static">{{model.f_collection.toFixed(2)}}</span> -->
      </div>
    </form>
    <div style="text-align:right;margin-top:80px;margin-right:50px;">
      <button class="btn btn-default width-60" @click="confirm()">撤销</button>
      <button class="btn btn-default width-60" @click="clean()" style="width:80px;margin-left:20px;">取&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;消</button>
    </div>
  </div>
</template>
<script>
/**
*综合业务
*卡表收费组件
*/

export default {
  title: '卡表收费',
  data () {
    return {
      model: {
        f_payment: '',
        f_pregas: '',
        f_preamount: '',
        f_totalcost: '',
        f_curbalance: '',
        f_collection: '',
        f_balance: '',
        f_canceltype: ''
      }
    }
  },
  props: ['row'],
  ready () {
    this.model.f_price_id = this.row.f_price_id
    this.model.f_user_id = this.row.f_user_id
    this.model.f_userinfo_id = this.row.f_userinfo_id
    // let data = {
    //   items: '*',
    //   tablename: 't_sellinggas',
    //   condition: 'f_user_id=' + "'" + this.model.f_user_id + "'" + 'and f_userinfo_id=' + "'" + this.model.f_userinfo_id + "'" + 'and f_charge_type=' + "'" + '卡表收费' + "'",
    //   orderitem: 'f_delivery_date desc'
    // }
    this.$resetpost('rs/sql/gasCancel', {data: {f_user_id: this.model.f_user_id}}, {resolveMsg: null, rejectMsg: null}).then((res) => {
      this.model.id = res.data[0].id
      this.model.f_pregas = res.data[0].f_pregas
      this.model.f_preamount = res.data[0].f_preamount
      this.model.f_curbalance = res.data[0].f_curbalance
      this.model.f_collection = res.data[0].f_collection
      this.model.f_balance = res.data[0].f_balance
      this.model.f_canceltype = res.data[0].f_canceltype
    }).catch((error) => {
      this.$dispatch('error', '收费撤销', this.row, error)
    })
  },
  watch: {
    'row' (val) {
      this.model.f_price_id = val.f_price_id
      this.model.f_user_id = val.f_user_id
      this.model.f_userinfo_id = val.f_userinfo_id
    }
  },
  methods: {
    confirm () {
      this.$CancelService.cardChargeCancel(this.model, this.row)
      .then(
        (res) => this.$dispatch('success', '收费撤销', this.row, res)
      ).catch(
        (error) => {
          if (error.status === 603) {
            this.$error('重复提交')
            return
          }
          this.$dispatch('error', '收费撤销', this.row, error)
        }
      )
    },
    clean () {
      this.$info('取消操作')
      this.$dispatch('cancelclean', this.row)
    }
  }
}
</script>

<style>
</style>
